<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2024/1/9
  Time: 11:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="header.jsp"%>
    <style>
        .center{
            padding-left: 15px;
            padding-right: 15px;
            padding-top: 5px;
        }
    </style>
</head>
<body class="center">
    <form action="/user?method=update" method="post">
        <input type="hidden" value="${user.id}" name="id"/>
        <div class="form-group">
            <label>用户名</label>
            <input type="text" class="form-control"  name="name" value="${user.name}"/>
        </div>
        <div class="form-group">
            <label>密码</label>
            <input type="text" class="form-control"  name="password" value="${user.password}"/>
        </div>
        <div class="form-group">
            <label>邮箱</label>
            <input type="text" class="form-control"  name="email" value="${user.email}"/>
        </div>
        <div class="form-group">
            <label>角色</label>
            <c:choose>
                <c:when test="${user.role==1}">
                    <input type="radio" value="1" name="role" checked/>超级管理员
                    <input type="radio" value="2" name="role"/>普通管理员
                </c:when>
                <c:when test="${user.role==2}">
                    <input type="radio" value="1" name="role" />超级管理员
                    <input type="radio" value="2" name="role" checked/>普通管理员
                </c:when>
            </c:choose>

        </div>
        <div class="form-group">
            <label>状态</label>
            <c:choose>
                <c:when test="${user.status==1}">
                    <input type="radio" value="1" name="status" checked/>正常
                    <input type="radio" value="0" name="status"/>禁用
                </c:when>
                <c:when test="${user.status==0}">
                    <input type="radio" value="1" name="status"/>正常
                    <input type="radio" value="0" name="status" checked/>禁用
                </c:when>
            </c:choose>

        </div>
        <div class="form-group">
            <label>封面</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <div class="layui-upload-list">
                        <img src="/pic/${user.image}" width="100px" height="100px" class="layui-upload-img" id="demo1">
                        <input value="${user.image}" type="hidden" name="image" id="imageId">
                        <p id="demoText"></p>
                    </div>
                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                </div>
            </div>
        </div>
        <input class="btn btn-primary" type="submit" value="编辑"/>
    </form>

    <script>
        layui.use(['upload'], function() {
            var upload = layui.upload;

            //常规使用 - 普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                ,url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(result){
                    if (result.code == 0) {
                        $('#imageId').val(result.data);
                        $('#demoText').html(''); //置空上传失败的状态
                    } else {
                        mylayer.errorMsg(result.msg);
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });

        });
    </script>
</body>
</html>
